package com.nursing.Dao;

import com.nursing.bean.CheckinCheckout;
import com.nursing.model.dto.CheckinCheckoutStatisticsDto;
import com.nursing.model.dto.ElderStatisticsDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CheckinCheckoutDao {
    @Select("SELECT * FROM checkin_checkout")
    List<CheckinCheckout> getAll();

    @Select("SELECT * FROM checkin_checkout WHERE id = #{id}")
    CheckinCheckout getById(Integer id);

    @Select("SELECT * FROM checkin_checkout WHERE elder_id = #{elderId}")
    List<CheckinCheckout> getByElderId(Integer elderId);

    @Insert("INSERT INTO checkin_checkout (elder_id, checkin_date, checkout_date, room_number) " +
            "VALUES (#{elderId}, #{checkinDate}, #{checkoutDate}, #{roomNumber})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(CheckinCheckout checkinCheckout);

    @Update("UPDATE checkin_checkout SET checkin_date = #{checkinDate}, checkout_date = #{checkoutDate}, " +
            "room_number = #{roomNumber} WHERE id = #{id}")
    void update(CheckinCheckout checkinCheckout);

    @Delete("DELETE FROM checkin_checkout WHERE id = #{id}")
    void delete(Integer id);


    @Select("SELECT COUNT(*) FROM checkin_checkout")
    Integer getCount();

    @Select("SELECT MONTH(checkin_date) AS month, COUNT(id) AS count " +
            "FROM checkin_checkout " +
            "WHERE YEAR(checkin_date) = YEAR(CURDATE()) " +
            "GROUP BY MONTH(checkin_date) " +
            "ORDER BY month")
    List<CheckinCheckoutStatisticsDto> getMonthlyCount();
}